Another wave of leak tweaks.
authorrobertlipe@gmail.com <robertlipe@gmail.com@f51c46e8-681c-474f-0cfe-069cfd0219fb>
Tue, 31 Dec 2013 20:41:41 +0000 (20:41 +0000)
committerrobertlipe@gmail.com <robertlipe@gmail.com@f51c46e8-681c-474f-0cfe-069cfd0219fb>
Tue, 31 Dec 2013 20:41:41 +0000 (20:41 +0000)
git-svn-id: http://gpsbabel.googlecode.com/svn/trunk@4683 f51c46e8-681c-474f-0cfe-069cfd0219fb

gpsbabel/compegps.cc
gpsbabel/garmin_txt.cc
gpsbabel/gtrnctr.cc
gpsbabel/humminbird.cc
gpsbabel/lowranceusr.cc
gpsbabel/lowranceusr4.cc
gpsbabel/route.cc

index 90b90dabe263d03622d9210bb1315d555db3bb3b..cd4e71efd84c2fcf993b6d1573d672a6fc8507cb 100644 (file)
@@ -185,7 +185,7 @@ parse_wpt(char* buff)
           *cx-- = '\0';
         }
         if (*c != '\0') {
-          wpt->shortname = xstrdup(c);
+          wpt->shortname = c;
         }
         break;
       case 2:
@@ -213,17 +213,12 @@ parse_wpt(char* buff)
         wpt->altitude = atof(c);
         break;
       case 7:
-        wpt->description = xstrdup(c);
+        wpt->description = c;
         break;
       default:
         if (col > 7) {
-#if NEW_STRINGS
           wpt->description += " ";
           wpt->description += c;
-#else
-          wpt->description = xstrappend(wpt->description, " ");
-          wpt->description = xstrappend(wpt->description, c);
-#endif
         }
       }
     }
@@ -340,7 +335,7 @@ parse_track_info(const char* buff, route_head* track)       /* "t" */
       case 0:
         break; /* unknown field */
       case 1:
-        track->rte_name = xstrdup(c);
+        track->rte_name = c;
         break;
       case 2:
         break; /* unknown field */
@@ -369,7 +364,7 @@ parse_rte_info(const char* buff, route_head* route) /* "R" */
       case 0:
         break;                         /* unknown field (colour?) */
       case 1:
-        route->rte_name = xstrdup(c);
+        route->rte_name = c;
         break;
       case 2:
         break;                         /* unknown field */
@@ -526,7 +521,7 @@ write_route_hdr_cb(const route_head* rte)
   if (name != NULL) {
     name = csv_stringclean(name, ",");
   } else {
-    name = xstrdup(" ");
+    name = " ";
   }
   gbfprintf(fout, "R  16711680,%s,1,-1\n", CSTR(name));
 }
index d4507704c6af092f5cd99b0abd5fc566c3c87a9d..8881654e4a6c895104374d5a3bf72c7fdd0642a6 100644 (file)
@@ -99,7 +99,7 @@ static int header_ct[unknown_header + 1];
 /* macros */
 
 #define IS_VALID_ALT(a) (((a) != unknown_alt) && ((a) < GARMIN_UNKNOWN_ALT))
-#define DUPSTR(a) (((a) != NULL) && ((a)[0] != 0)) ? xstrdup((a)) : NULL
+#define DUPSTR(a) (((a) != NULL) && ((a)[0] != 0)) ? ((a)) : NULL
 
 static char* opt_datum = NULL;
 static char* opt_dist = NULL;
index a0f75836d2c09e08de4cfb32f40f731c50906218..10ba6111738c961e2404a358a795b63d3b7921d4 100644 (file)
@@ -474,7 +474,7 @@ gtc_trk_s(const xg_string unused, const QXmlStreamAttributes* unusedattrs)
 void
 gtc_trk_ident(xg_string args, const QXmlStreamAttributes* unused)
 {
-  trk_head->rte_name = xstrdup(args);
+  trk_head->rte_name = args;
 }
 
 void
@@ -506,7 +506,7 @@ gtc_trk_pnt_e(xg_string args, const QXmlStreamAttributes* unused)
       char cbuf[10];
       waypoint* wpt_lap_s = waypt_dupe(wpt_tmp);
       snprintf(cbuf, sizeof(cbuf), "LAP%03d", lap_ct);
-      wpt_lap_s->shortname = xstrdup(cbuf);
+      wpt_lap_s->shortname = cbuf;
       waypt_add(wpt_lap_s);
       lap_s = 0;
     }
@@ -654,9 +654,7 @@ gtc_wpt_pnt_e(xg_string args, const QXmlStreamAttributes* unused)
   if (wpt_tmp->longitude != 0. && wpt_tmp->latitude != 0.) {
     /* Add the begin position of a CourseLap as
     a waypoint. */
-    char* cbuf;
-    xasprintf(&cbuf, "LAP%03d", lap_ct);
-    wpt_tmp->shortname = cbuf;
+    wpt_tmp->shortname = QString().sprintf("LAP%03d", lap_ct);
     waypt_add(wpt_tmp);
   } else {
     waypt_free(wpt_tmp);
@@ -692,9 +690,9 @@ void gtc_wpt_notes(const QString& args, const QXmlStreamAttributes* unused)
 void
 gtc_wpt_ident(xg_string args, const QXmlStreamAttributes* unused)
 {
-  wpt_tmp->shortname = xstrdup(args);
+  wpt_tmp->shortname = args;
   /* Set also as notes for compatibility with garmin usb format */
-  wpt_tmp->notes = xstrdup(args);
+  wpt_tmp->notes = args;
 }
 
 void
@@ -718,7 +716,7 @@ gtc_wpt_icon(xg_string args, const QXmlStreamAttributes* unused)
 void
 gtc_wpt_notes(xg_string args, const QXmlStreamAttributes* unused)
 {
-  wpt_tmp->description = xstrdup(args);
+  wpt_tmp->description = args;
 }
 #endif
 
index 51d2776d366a831a4d9c63195c96249c0b92faa1..08d1ebadc69835fabe0e26268f3a34dfcd9758dd 100644 (file)
@@ -287,7 +287,11 @@ humminbird_read_wpt(gbfile* fin)
 
   wpt = waypt_new();
 
-  wpt->shortname = xstrndup(w.name, sizeof(w.name));
+  // Could probably find a way to eliminate the alloc/copy.
+  char *s = xstrndup(w.name, sizeof(w.name));
+  wpt->shortname = s;
+  xfree(s);
+
   wpt->SetCreationTime(w.time);
 
   guder = gudermannian_i1924(w.north);
@@ -358,7 +362,10 @@ humminbird_read_route(gbfile* fin)
         if (rte == NULL) {
           rte = route_head_alloc();
           route_add_head(rte);
-          rte->rte_name = xstrndup(hrte.name, sizeof(hrte.name));
+          // TODO: find a way to eliminate the copy.
+          char *s = xstrndup(hrte.name, sizeof(hrte.name));
+          rte->rte_name = s;
+          xfree(s);
           /* rte->rte_num = hrte.num + 1; only internal number */
         }
         route_add_wpt(rte, waypt_dupe(wpt));
@@ -419,7 +426,10 @@ humminbird_read_track(gbfile* fin)
   trk = route_head_alloc();
   track_add_head(trk);
 
-  trk->rte_name = xstrndup(th.name, sizeof(th.name));
+  // TODO: find a way to eliminate the copy.
+  char *s = xstrndup(th.name, sizeof(th.name));
+  trk->rte_name = s;
+  xfree(s);
   trk->rte_num  = th.trk_num;
 
   /* We create one wpt for the info in the header */
index 2f1e1d1f710b6e8293b02bb62bf618289d378f5e..a566caaa44a4b5c0285cc083fe6ece8e539d1709 100644 (file)
@@ -395,7 +395,7 @@ lowranceusr_parse_waypt(waypoint* wpt_tmp)
   text_len = lowranceusr_readstr(&buff[0], MAXUSRSTRINGSIZE, file_in);
   if (text_len) {
     buff[text_len] = '\0';
-    wpt_tmp->shortname = xstrdup(buff);
+    wpt_tmp->shortname = buff;
   }
 
   if (global_opts.debug_level >= 1)
@@ -405,7 +405,7 @@ lowranceusr_parse_waypt(waypoint* wpt_tmp)
   text_len = lowranceusr_readstr(&buff[0], MAXUSRSTRINGSIZE, file_in);
   if (text_len) {
     buff[text_len] = '\0';
-    wpt_tmp->description = xstrdup(buff);
+    wpt_tmp->description = buff;
   }
   /* Time is number of seconds since Jan. 1, 2000 */
   waypt_time = gbfgetint32(file_in);
@@ -470,7 +470,7 @@ lowranceusr_parse_routes(void)
     text_len = lowranceusr_readstr(&buff[0], MAXUSRSTRINGSIZE, file_in);
     if (text_len) {
       buff[text_len] = '\0';
-      rte_head->rte_name = xstrdup(buff);
+      rte_head->rte_name = buff;
     }
 
     /* num Legs */
@@ -520,7 +520,7 @@ lowranceusr_parse_icons(void)
       wpt_tmp->longitude = lon_mm_to_deg(gbfgetint32(file_in));
       wpt_tmp->altitude = 0;
       snprintf(buff, sizeof(buff), "Icon %d", i+1);
-      wpt_tmp->shortname = xstrdup(buff);
+      wpt_tmp->shortname = buff;
       /* symbol */
       wpt_tmp->icon_descr = lowranceusr_find_desc_from_icon_number(gbfgetint32(file_in));
       waypt_add(wpt_tmp);
@@ -560,7 +560,7 @@ lowranceusr_parse_trails(void)
 
     if (text_len) {
       buff[text_len] = '\0';
-      trk_head->rte_name = xstrdup(buff);
+      trk_head->rte_name = buff;
     }
 
     if (global_opts.debug_level >= 1) {
@@ -602,7 +602,7 @@ lowranceusr_parse_trails(void)
           if (!buff[0] && seg_break && j) {
             trk_tmp = route_head_alloc();
             trk_tmp->rte_num = ++trk_num;
-            trk_tmp->rte_name = xstrdup(trk_head->rte_name);
+            trk_tmp->rte_name = trk_head->rte_name;
             track_add_head(trk_tmp);
             trk_head = trk_tmp;
           }
index 5b7a2f245654c4fc3db7b4253772726d399163ee..8761b4d5a0bcc1fd129e1cc691b33f8b4f711068 100644 (file)
@@ -402,7 +402,7 @@ lowranceusr4_parse_waypoints(void)
     text_len = lowranceusr4_readstr(&buff[0], MAXUSRSTRINGSIZE, file_in, 2);
     if (text_len) {
       buff[text_len] = '\0';
-      wpt_tmp->shortname = xstrdup(buff);
+      wpt_tmp->shortname = buff;
     }
 
     /* Long/Lat */
@@ -427,7 +427,7 @@ lowranceusr4_parse_waypoints(void)
     text_len = lowranceusr4_readstr(&buff[0], MAXUSRSTRINGSIZE, file_in, 2);
     if (text_len) {
       buff[text_len] = '\0';
-      wpt_tmp->description = xstrdup(buff);
+      wpt_tmp->description = buff;
     }
 
     /* Alarm radius; XXX: I'm not sure what the units are here,
@@ -544,7 +544,7 @@ lowranceusr4_parse_routes(void)
     text_len = lowranceusr4_readstr(&buff[0], MAXUSRSTRINGSIZE, file_in, 2);
     if (text_len) {
       buff[text_len] = '\0';
-      rte_head->rte_name = xstrdup(buff);
+      rte_head->rte_name = buff;
     }
 
     num_legs = gbfgetint32(file_in);
@@ -643,7 +643,7 @@ lowranceusr4_parse_trails(void)
     text_len = lowranceusr4_readstr(&buff[0], MAXUSRSTRINGSIZE, file_in, 2);
     if (text_len) {
       buff[text_len] = '\0';
-      trk_head->rte_name = xstrdup(buff);
+      trk_head->rte_name = buff;
     }
 
     /* Flags, discard for now */
@@ -656,7 +656,7 @@ lowranceusr4_parse_trails(void)
     text_len = lowranceusr4_readstr(&buff[0], MAXUSRSTRINGSIZE, file_in, 2);
     if (text_len) {
       buff[text_len] = '\0';
-      trk_head->rte_desc = xstrdup(buff);
+      trk_head->rte_desc = buff;
     }
 
     /* Creation date/time, discard for now */
index 1788d8fc669dfb7d7cd1f2cc86a3ae9ad8a72de1..ec348e589b7a3e124b6147bf08a3f793fb34a90b 100644 (file)
@@ -77,14 +77,6 @@ route_head_alloc(void)
 static void
 any_route_free(route_head* rte)
 {
-#if !NEW_STRINGS
-  if (rte->rte_name) {
-    xfree(rte->rte_name);
-  }
-  if (rte->rte_desc) {
-    xfree(rte->rte_desc);
-  }
-#endif
   waypt_flush(&rte->waypoint_list);
   if (rte->fs) {
     fs_chain_destroy(rte->fs);
@@ -153,11 +145,7 @@ common_route_by_name(queue* routes, const char* name)
 
   QUEUE_FOR_EACH(routes, elem, tmp) {
     rte = (route_head*) elem;
-#if NEW_STRINGS
     if (rte->rte_name == name) {
-#else
-    if (0 == strcmp(rte->rte_name, name)) {
-#endif
       return rte;
     }
   }
@@ -185,15 +173,8 @@ any_route_add_wpt(route_head* rte, waypoint* wpt, int* ct, int synth, const QStr
   if (ct) {
     (*ct)++;
   }
-#if NEW_STRINGS
   if (synth && wpt->shortname.isEmpty()) {
-    char *t;
-    xasprintf(&t, "%s%0*d", CSTRc(namepart), number_digits, *ct);
-    wpt->shortname = t;
-#else
-  if (synth && !wpt->shortname) {
-    xasprintf(&wpt->shortname,"%s%0*d", CSTR(namepart), number_digits, *ct);
-#endif
+    wpt->shortname = QString().sprintf("%s%0*d", CSTRc(namepart), number_digits, *ct);
     wpt->wpt_flags.shortname_is_synthetic = 1;
   }
   update_common_traits(wpt);
@@ -246,11 +227,7 @@ route_find_waypt_by_name(route_head* rh, const char* name)
 
   QUEUE_FOR_EACH(&rh->waypoint_list, elem, tmp) {
     waypoint* waypointp = (waypoint*) elem;
-#if NEW_STRINGS
     if (waypointp->shortname == name) {
-#else
-    if (0 == strcmp(waypointp->shortname, name)) {
-#endif
       return waypointp;
     }
   }
@@ -438,8 +415,8 @@ route_copy(int* dst_count, int* dst_wpt_count, queue** dst, queue* src)
     route_head* rte_old = (route_head*)elem;
 
     rte_new = route_head_alloc();
-    rte_new->rte_name = xstrdup(rte_old->rte_name);
-    rte_new->rte_desc = xstrdup(rte_old->rte_desc);
+    rte_new->rte_name = rte_old->rte_name;
+    rte_new->rte_desc = rte_old->rte_desc;
     rte_new->rte_url = rte_old->rte_url;
     rte_new->fs = fs_chain_copy(rte_old->fs);
     rte_new->rte_num = rte_old->rte_num;
@@ -601,10 +578,6 @@ void track_recompute(const route_head* trk, computed_trkdata** trkdatap)
   double tot_hrt = 0.0;
   int pts_cad = 0;
   double tot_cad = 0.0;
-#if NEW_STRINGS
-#else
-  char tkptname[100];
-#endif
   computed_trkdata* tdata = (computed_trkdata*)xcalloc(1, sizeof(computed_trkdata));
 
   if (trkdatap) {
@@ -707,15 +680,8 @@ void track_recompute(const route_head* trk, computed_trkdata** trkdatap)
       }
     }
     prev = thisw;
-#if NEW_STRINGS
     if (thisw->shortname.isEmpty()) {
       thisw->shortname = QString("%1-%2").arg(trk->rte_name).arg(tkpt);
-#else
-    if (!thisw->shortname || !thisw->shortname[0]) {
-      snprintf(tkptname, sizeof(tkptname), "%s-%d",
-               trk->rte_name ? CSTRc(trk->rte_name) : "" , tkpt);
-      thisw->shortname = xstrdup(tkptname);
-#endif
     }
     tkpt++;
   }